package io.xxx.walle.task;

import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    /**
     * 查询任务列表
     */
    @GetMapping
    public Page<Task> getPage(
            @PageableDefault Pageable pageable,
            @RequestParam String name
    ) {
        return taskService.getPage(pageable, name);
    }

    /**
     * 查询任务详情
     */
    @GetMapping("/{id:\\d+}")
    public Optional<Task> get(@PathVariable Long id) {
        return taskService.get(id);
    }

    /**
     * 保存任务信息
     */
    @PostMapping
    public Long save(Task task) {
        return taskService.save(task);
    }
}
